/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include "MAddressIPX.h"

//---------------------------------------------------------------------------

MAddressIPX::MAddressIPX(void)
{
	Initialize();
}

MAddressIPX::~MAddressIPX(void)
{
}

//---------------------------------------------------------------------------

void MAddressIPX::Initialize(void)
{
	net[0] = 0x00;
	net[1] = 0x00;
	net[2] = 0x00;
	net[3] = 0x00;

	host[0] = 0x00;
	host[1] = 0x00;
	host[2] = 0x00;
	host[3] = 0x00;
	host[4] = 0x00;
	host[5] = 0x00;
}

//---------------------------------------------------------------------------

void MAddressIPX::LoadFromPointer(MAddressIPX* aiIn)
{
	int i;

	Initialize();

	for(i=0; i<4; i++) net[i]  = aiIn->net[i];
	for(i=0; i<6; i++) host[i] = aiIn->host[i];
}

//---------------------------------------------------------------------------

void MAddressIPX::SetNet(BYTE* dataIn)
{
	int i;

	if(dataIn==NULL){
		for(i=0; i<4; i++) net[i] = 0x00;
		return;
	}

	for(i=0; i<4; i++) net[i] = dataIn[i];
}

void MAddressIPX::SetHost(BYTE* dataIn)
{
	int i;

	if(dataIn==NULL){
		for(i=0; i<6; i++) host[i] = 0x00;
		return;
	}

	for(i=0; i<6; i++) host[i] = dataIn[i];
}

//---------------------------------------------------------------------------

CString MAddressIPX::GetS(void)
{
	CString str;

	str.Format(_T("%02X%02X%02X%02X.%02X%02X%02X%02X%02X%02X"),
		net[0], net[1], net[2], net[3],
		host[0], host[1], host[2], host[3], host[4], host[5]);
	return str;
}

//---------------------------------------------------------------------------

bool MAddressIPX::IsEmpty(void)
{
	if(net[0]!=0x00)  return false;
	if(net[1]!=0x00)  return false;
	if(net[2]!=0x00)  return false;
	if(net[3]!=0x00)  return false;

	if(host[0]!=0x00) return false;
	if(host[1]!=0x00) return false;
	if(host[2]!=0x00) return false;
	if(host[3]!=0x00) return false;
	if(host[4]!=0x00) return false;
	if(host[5]!=0x00) return false;

	return true;
}

//---------------------------------------------------------------------------

bool MAddressIPX::IsEqualWith(MAddressIPX* aiIn)
{
	if(aiIn==NULL) return false;

	if(net[0]!=aiIn->net[0]) return false;
	if(net[1]!=aiIn->net[1]) return false;
	if(net[2]!=aiIn->net[2]) return false;
	if(net[3]!=aiIn->net[3]) return false;

	if(host[0]!=aiIn->host[0]) return false;
	if(host[1]!=aiIn->host[1]) return false;
	if(host[2]!=aiIn->host[2]) return false;
	if(host[3]!=aiIn->host[3]) return false;
	if(host[4]!=aiIn->host[4]) return false;
	if(host[5]!=aiIn->host[5]) return false;

	return true;
}

//---------------------------------------------------------------------------
